      <div class="templatemo-content-wrapper">
        <div class="templatemo-content">
          <ol class="breadcrumb">
            <li><a href="<?=site_url()?>/order/index">订单管理</a></li>
            <li class="active">订单列表</li>
          </ol>
           <div class="row margin-bottom-30">
            <div class="col-md-12">
              	<input type="text" id="date" name="date" value="<?php echo date('Y-m-d',time()); ?>">
            	<button class="btn btn-primary" id="order_btn">导出订单</button>
            	<button class="btn btn-primary" id="orderdetail_btn">导出采购单</button> 
            	<button class="btn btn-primary" id="sort_btn">导出分拣表</button>
            	<button class="btn btn-primary" id="linereport_btn">线上日报单</button>
            	<button class="btn btn-primary" id="report_btn">线下日报单</button>
            	<button class="btn btn-primary" id="allreport_btn">全部日报单</button>
            	<button class="btn btn-primary" id="quotation_btn">导出报价单</button>
            	<button class="btn btn-primary" id="supply_btn">供应商采购单</button>
            	<button class="btn btn-primary" id="nosupply_btn">非供应商采购单</button>
            </div>
          </div> 
              <div>
              		<input type="text" id="name" name="name" value="">
            		<select id="state">
            			<option value="-2" <?php if($state ==-2) echo "selected"; ?>>所有</option>
            			<option value="0" <?php if($state ==0) echo "selected"; ?>>待支付</option>
            			<option value="1" <?php if($state ==1) echo "selected"; ?>>已支付</option>
            			<option value="2" <?php if($state ==2) echo "selected"; ?>>拣货中</option>
            		    <option value="3" <?php if($state ==3) echo "selected"; ?>>配送中</option>
            			<option value="4" <?php if($state ==4) echo "selected"; ?>>已完成</option>
            		</select>
            		<select id="del">
            			<option value="-1" <?php if($del ==-1) echo "selected"; ?>>所有</option>
            			<option value="0" <?php if($del ==0) echo "selected"; ?>>有效订单</option>
            			<option value="1" <?php if($del ==1) echo "selected"; ?>>无效订单</option>
            		</select>
            		<button class="btn btn-primary" id="submit_btn">搜  索</button>
            		<span>
            		当天订单数：<?php  echo $ordernum;?>
            		</span>
            		<span>
            		当天营业额(元)：<?php  echo $todaytotal;?>
            		</span>
            		<span>
            		昨天营业额(元)：<?php  echo $yestotal;?>
            		</span>
            		<span>
            		总营业额(元)：<?php  echo $totals;?>
            		</span>
            		<button class="btn btn-primary" id="order_finish">一键完成</button>
            		<div>
            	<button class="btn btn-primary" id="order_check">一键确认</button>
            	<button class="btn btn-primary" id="order_send">一键配送</button>
            	<button class="btn btn-primary" id="dispatch_btn">车辆调度</button>
            	<button class="btn btn-primary" id="purprice_btn">录入进货价</button>
            	<button class="btn btn-primary" id="newsort_btn">选择分拣单</button>
            	<a class="btn btn-primary" id="addorder_btn" href="<?php echo site_url('order/addorder')?>">添加订单</a>       
            </div>
            </div>
          <div class="row">
            <div class="col-md-12">
             <!-- <div class="btn-group pull-right" id="templatemo_sort_btn">
                <button type="button" class="btn btn-default">Sort by</button>
                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                  <span class="caret"></span>
                  <span class="sr-only">Toggle Dropdown</span>
                </button>
                <ul class="dropdown-menu" role="menu">
                  <li><a href="#">First Name</a></li>
                  <li><a href="#">Last Name</a></li>
                  <li><a href="#">Username</a></li>
                </ul>
             </div>-->
              
              <div class="table-responsive">
                <h4 class="margin-bottom-15">订单列表</h4>
                <table class="table table-striped table-hover table-bordered">
                  <thead>
                    <tr>
                      <th width="2%">ID</th>
                      <th width="20%">操作</th>
                      <th width="10%">店名</th>
                      <th width="5%">用户</th>
                      <th width="8%">下单时间</th>
                      <th width="6%">支付方式</th>
                      <th width="8%">收货时间</th>
                      <th width="8%">备注</th>
                      <th width="5%">状态</th>
                      <th width="5%">推广员</th>
                      <th width="3%">评分</th>
                      <th width="10%">订单编号</th>
                    </tr>
                  </thead>
                  <tbody>
                  	<?php foreach ($orders as $item):?>
                    <tr> 
                      <td>
                      		<a href="<?php echo site_url('order/index/state/-2/del/-1/name/'.$item['shopname'])?>" class="btn btn-link">
                      		<?php 
                      			if($item['second']==1){
                      				echo  '<span style="color:red;">'.'***'.$item['id'].'</span>';
                      			}elseif(empty($item['lng'])){
                      				echo '<span style="color:green;">'.$item['id'].'</span>';
                      			}else{
                      				echo $item['id'];
                      			}
                      		?>
                      		</a>
                      </td>
                      <td>
                        <?php 
                        if($item['state'] == 1 || ($item['state'] == 0&&$item['payment_mode']==3) )
                        {
                        	echo '<a href="#" class="btn btn-link check" data-id="'.$item['id'].'" >确认订单</a>';
						}
						 if($item['state'] == 2)
                        {
                        	echo '<a href="#" class="btn btn-link send" data-id="'.$item['id'].'" >开始配送</a>';
						}		
                        if($item['state'] == 3 || $item['state'] == 5)
                        {
                        	echo '<a href="#" class="btn btn-link finish" data-id="'.$item['id'].'" mode="'.$item['payment_mode'].'" >完成订单</a>';
						}
						if($item['state'] == 3&&$item['payment_mode']==3)
                        {
                        	echo '<a href="#" class="btn btn-link unpay" data-id="'.$item['id'].'"  >未结算</a>';
						}		
                        ?>	
                        <?php 
                        	echo '<a href="'.site_url('order/detail/id/'.$item['id']).'" class="btn btn-link detail">订单详情</a>'; 
                        ?>
                       </td>
                       <td><?php echo $item['shopname'].'('.$item['district'].')';?></td>
                      <td><a href="<?php echo site_url('user/index/name/'.$item['userid'])?>" class="btn btn-link"><?php echo $item['contact'];?></a></td>
                      <td><?php echo $item['order_time'];?></td>
                      <td><?php 
                      	if($item['payment_mode']==1){
                      		echo "支付宝支付";
                      	}
                      	if($item['payment_mode']==2){
                      		echo "微信支付";
                      	}
                      	if($item['payment_mode']==3){
                      		echo "货到付款";
                      	}
						if($item['payment_mode']==4){
                      		echo "余额支付";
                      	}
                      ?></td>
                     <td><?php echo date("Y-m-d",strtotime($item['receive_time'])).' '.$item['early_time'].'-'.$item['late_time'];?></td>
                      <td>
                      	<?php echo $item['note'];?>
                      	<a href="<?php echo site_url('order/note/id/'.$item['id'])?>" class="btn btn-link">修改</a>
                      </td>
                       <td><?php 
                       	if($item['state'] == -1&&$item['merge'] ==0)
                        {
                        	echo "已取消";
                        }
						if($item['state'] == -1&&$item['merge'] ==1)
                        {
                        	echo "已合并";
                        }
                        if($item['state'] == 0)
                        {
                        	echo "待支付";
                        }
						if($item['state'] == 1)
                        {
                        	echo "已支付";
                        }
						if($item['state'] == 2)
                        {
                        	echo "拣货中";
                        }
						if($item['state'] == 3)
                        {
                        	echo "配送中";
                        }
						if($item['state'] == 4)
                        {
                        	echo "已完成";
                        }
						if($item['state'] == 5)
                        {
                        	echo "已配送未支付";
                        }
                        ?>
                          <?php
                      	    	 if($item['del'] == 0){
                        			echo '<a href="#" class="btn btn-link del" data-id="'.$item['id'].'" >删除</a>';
                       			 }
								if($item['del'] == 1){
                        			echo '<a href="#" class="btn btn-link rec" data-id="'.$item['id'].'" >恢复</a>';
                        		}
                      	    ?>
                        </td>
                        <td>
                        	<?php if(!empty($item['promoter'])) {
									echo $item['promoter'];
							}?>
                        </td>
                        <td>
                        	<?php echo $item['score'];?>
                        </td>
                        <td>
                      		 <?php echo $item['orderno'];?>
                      	    <select id="state<?php echo $item['id'];?>">
            					<option value="0">待支付</option>
            					<option value="1">已支付</option>
            					<option value="2">拣货中</option>
            		    		<option value="3">配送中</option>
            					<option value="4">已完成</option>
            				</select>
            				<button class="update" data-id="<?php echo $item['id'];?>" >确认</button>
                      </td>
                    </tr>
                     <?php endforeach;?>
                  </tbody>
                </table>
              </div>
               <?php  echo $links; ?>
              <!--<ul class="pagination pull-right">
                <li class="disabled"><a href="#">&laquo;</a></li>
                <li class="active"><a href="#">1 <span class="sr-only">(current)</span></a></li>
                <li><a href="#">2 <span class="sr-only">(current)</span></a></li>
                <li><a href="#">3 <span class="sr-only">(current)</span></a></li>
                <li><a href="#">4 <span class="sr-only">(current)</span></a></li>
                <li><a href="#">5 <span class="sr-only">(current)</span></a></li>
                <li><a href="#">&raquo;</a></li>
              </ul>  -->
            </div>
          </div><br /><br />
          <div class="col-md-12">
          	<hr />
             <ul class="nav nav-pills">
                <li class="active"><a href="<?=site_url()?>/order/supplierorderlist">供货商订单</a></li>
                 <li class="active"><a href="#" class="comment">自动评分</a></li>
             </ul> 
             </div>
        </div>
      </div>
      
    <script>
	$(document).ready(function() {
		$('#date').datepicker({
			dateFormat: 'yy-mm-dd',
			monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
			dayNamesMin: ['日','一','二','三','四','五','六']
		});
		$("#order_btn").click(function() {
			var date = $("#date").val();
			var url = "<?php echo site_url('order/exportOrders')?>";
			window.location.href=url+"/date/"+date;
		});
		$("#orderdetail_btn").click(function() {
			var date = $("#date").val();
			var url = "<?php echo site_url('order/exportOrderdetails')?>";
			window.location.href=url+"/date/"+date;
		});
		$("#sort_btn").click(function() {
			var date = $("#date").val();
			var url = "<?php echo site_url('order/exportSort')?>";
			window.location.href=url+"/date/"+date;
		});
		$("#linereport_btn").click(function() {
			var date = $("#date").val();
			var url = "<?php echo site_url('order/exportReport')?>";
			window.location.href=url+"/date/"+date+"/payment/1";
		});
		$("#report_btn").click(function() {
			var date = $("#date").val();
			var url = "<?php echo site_url('order/exportReport')?>";
			window.location.href=url+"/date/"+date+"/payment/2";
		});
		$("#allreport_btn").click(function() {
			var date = $("#date").val();
			var url = "<?php echo site_url('order/exportReport')?>";
			window.location.href=url+"/date/"+date+"/payment/0";
		});
		$("#quotation_btn").click(function() {
			var date = $("#date").val();
			var url = "<?php echo site_url('order/exportQuotation')?>";
			window.location.href=url+"/date/"+date;
		});
		$("#supply_btn").click(function() {
			var date = $("#date").val();
			var url = "<?php echo site_url('order/exportSupply')?>";
			window.location.href=url+"/date/"+date;
		});
		$("#nosupply_btn").click(function() {
			var date = $("#date").val();
			var url = "<?php echo site_url('order/exportNosupply')?>";
			window.location.href=url+"/date/"+date;
		});
		$("#submit_btn").click(function() {
			var state = $("#state").val();
			var del = $("#del").val();
			var name = $("#name").val();
			var url = "<?php echo site_url('order/index')?>";
			window.location.href=url+"/state/"+state+"/del/"+del+"/name/"+name;
		});
		$("#name").keydown(function(e) {
			if(e.keyCode == 13) {
				var state = $("#state").val();
				var del = $("#del").val();
				var name = $("#name").val();
				var url = "<?php echo site_url('order/index')?>";
				window.location.href=url+"/state/"+state+"/del/"+del+"/name/"+name;
			}
		});
		$("#dispatch_btn").click(function() {
			var date = $("#date").val();
			var url = "<?php echo site_url('dispatch/index')?>"+"/date/"+date;
			window.open(url,'_blank');
		});
		$("#purprice_btn").click(function() {
			var date = $("#date").val();
			var url = "<?php echo site_url('order/importPrices')?>";
			window.location.href=url+"/date/"+date;
		});
		$("#newsort_btn").click(function() {
			var date = $("#date").val();
			var url = "<?php echo site_url('order/selectsort')?>";
			window.location.href=url+"/date/"+date;
		});
		$(".del").click(function() {
			if(confirm("确定删除该订单吗？"))
			{
			var id = $(this).attr("data-id");
			$.ajax({
				url : '<?php echo site_url('order/setdel')?>',
				type : "post",
				async : true,
				data : {
					'id' : id,
					'del':1,
					'state':-1
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
				}
			});
			}
		});
		$(".rec").click(function() {
			if(confirm("确定恢复该订单吗？"))
			{
			var id = $(this).attr("data-id");
			$.ajax({
				url : '<?php echo site_url('order/setdel')?>',
				type : "post",
				async : true,
				data : {
					'id' : id,
					'del':0,
					'state':0
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
				}
			});
			}
		});
		$(".check").click(function() {
			if(confirm("确定确认该订单吗？"))
			{
			var id = $(this).attr("data-id");
			$.ajax({
				url : '<?php echo site_url('order/edit')?>',
				type : "post",
				async : true,
				data : {
					'id' : id,
					'state':2
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
				}
			});
			}
		});
		$(".send").click(function() {
			if(confirm("确定配送该订单吗？"))
			{
			var id = $(this).attr("data-id");
			$.ajax({
				url : '<?php echo site_url('order/edit')?>',
				type : "post",
				async : true,
				data : {
					'id' : id,
					'state':3
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
				}
			});
			}
		});
		$(".finish").click(function() {
			if(confirm("确定完成该订单吗？"))
			{
			var id = $(this).attr("data-id");
			var mode = $(this).attr("mode");
			$.ajax({
				url : '<?php echo site_url('order/edit')?>',
				type : "post",
				async : true,
				data : {
					'id' : id,
					'state':4,
					'payment':mode
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
				}
			});
			}
		});
		$(".unpay").click(function() {
			if(confirm("确定该订单未结算吗？"))
			{
			var id = $(this).attr("data-id");
			$.ajax({
				url : '<?php echo site_url('order/edit')?>',
				type : "post",
				async : true,
				data : {
					'id' : id,
					'state':5
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
				}
			});
			}
		});
		$(".comment").click(function() {
			if(confirm("确定自动评分吗？"))
			{
			$.ajax({
				url : '<?php echo site_url('order/comment')?>',
				type : "post",
				async : true,
				data : {
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
					}else{
						alert(data.msg);
					}
				}
			});
			}
		});
		$(".update").click(function() {
			var orderid = $(this).attr("data-id");
			var state = $("#state"+orderid).val();
			$.ajax({
				url : '<?php echo site_url('order/edit')?>',
				type : "post",
				async : false,
				data : {
					'id':orderid,
					'state':state
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
					
				}
			});
		});
		$("#order_check").click(function() {
			if(confirm("确定一键确认订单吗？"))
			{
			$.ajax({
				url : '<?php echo site_url('order/oneclick')?>',
				type : "post",
				async : true,
				data : {
					'state':2
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
				}
			});
			}
		});
		$("#order_send").click(function() {
			if(confirm("确定一键配送订单吗？"))
			{
			$.ajax({
				url : '<?php echo site_url('order/oneclick')?>',
				type : "post",
				async : true,
				data : {
					'state':3
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
				}
			});
			}
		});
		$("#order_finish").click(function() {
			if(confirm("确定一键完成订单吗？"))
			{
			$.ajax({
				url : '<?php echo site_url('order/oneclick')?>',
				type : "post",
				async : true,
				data : {
					'state':4
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
				}
			});
			}
		});
	}); 
</script>